package com.gxa.meiye.admin.controller.lzj;


import com.gxa.meiye.admin.service.ShopOrderService;
import com.gxa.meiye.core.common.JsonResult;
import com.gxa.meiye.core.common.ResponseData;
import com.gxa.meiye.core.pojo.domain.Order;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@Api(value = "Order",tags = "订单修改接口")
public class ShopOrderController {
    @Autowired
    private ShopOrderService shopOrderService;
    //订单查询
    @ResponseBody
    @ApiOperation("订单查询")
    @GetMapping("/order/query")
    public Map select(String phone){
        List<Order> list = shopOrderService.list(phone);
        JsonResult jsonResult=new JsonResult();
        if (StringUtils.isEmpty(list)){
            jsonResult.setCode("1");
            jsonResult.setMsg("查询成功");
            jsonResult.setData(list);
        }
        return jsonResult.getMap();
    }

    //查询美体师电话
    @ResponseBody
    @ApiOperation("查询电话")
    @GetMapping("/order/phone")
    public ResponseData queryPhone(String phone){
        return null;
    }


    //修改订单为已支付
    @ResponseBody
    @ApiOperation("修改订单为已支付")
    @PostMapping("/order/updateZF")
    public Map successful(String orderNumber,String serialNumber) {
        Integer update = shopOrderService.update(orderNumber, serialNumber);
        JsonResult jsonResult = new JsonResult();
        if (update != 0) {
            jsonResult.setCode("1");
            jsonResult.setMsg("已支付");
        }
        jsonResult.setCode("0");

        return jsonResult.getMap();
    }
    //修改订单为申请退款
    @ResponseBody
    @ApiOperation("修改订单为申请退款中")
    @PostMapping("/order/updateTKing")
    public Map refund(String orderNumber){
        Integer integer = shopOrderService.updateRe(orderNumber);
        JsonResult jsonResult=new JsonResult();
        if (integer!=0){
            jsonResult.setCode("1");
            jsonResult.setMsg("退款中");
        }
        return  jsonResult.getMap();
    }
    //退款成功修改状态
    @ResponseBody
    @ApiOperation("修改订单为已退款")
    @PostMapping("/order/updateTKstuats")
    public Map refundSuccessfulUpdate(String orderNumber){
        Integer integer = shopOrderService.updateRefund(orderNumber);
        JsonResult jsonResult=new JsonResult();
        if (integer!=0){
            jsonResult.setCode("1");
            jsonResult.setMsg("修改成功");
            return jsonResult.getMap();
        }
        jsonResult.setCode("0");
        jsonResult.setMsg("修改失败");
        return jsonResult.getMap();
    }

    //修改订单为已退款
    @ResponseBody
    @ApiOperation("修改订单为已退款")
    @PostMapping("/order/updateTK")
    public Map refundSuccessful(String orderNumber){
        String s = shopOrderService.selectLiuSui(orderNumber);
        JsonResult jsonResult=new JsonResult();
        if (StringUtils.isEmpty(s)){
            jsonResult.setCode("0");
            jsonResult.setMsg("查询失败");
            return  jsonResult.getMap();
        }
        jsonResult.setCode("1");
        jsonResult.setData(s);
        return  jsonResult.getMap();
    }

    //修改订单为撤销退款
    @ResponseBody
    @ApiOperation("修改订单为撤销退款")
    @PostMapping("/order/updateCX")
    public Map CancelRefund(String orderNumber){
        Integer integer = shopOrderService.updateCancel(orderNumber);
        JsonResult jsonResult=new JsonResult();
        if (integer!=0){
            jsonResult.setCode("1");
            jsonResult.setMsg("取消成功");
        }
        return  jsonResult.getMap();
    }


    //修改订单为已取消
    @ResponseBody
    @ApiOperation("修改订单为取消")
    @PostMapping("/order/updateQX")
    public Map Canceled(String orderNumber,String reason,String content){
        Integer integer = shopOrderService.addCancel(orderNumber, reason, content);
        JsonResult jsonResult=new JsonResult();
        if (integer!=0){
            Integer cancel = shopOrderService.Cancel(orderNumber);
            if (cancel!=0){
                jsonResult.setCode("1");
                jsonResult.setMsg("取消成功");
            }
        }
        return  jsonResult.getMap();
    }

}
